package com.ssy.lingxi.report.repository.settleaccount;

import com.ssy.lingxi.report.entity.settleaccount.MemberSettlementDO;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import java.util.List;

/**
 * 会员结算
 * @author 伍将
 * @date 2020/10/23
 * @version 2.0.0
 */
public interface MemberSettlementRepository extends JpaRepository<MemberSettlementDO, Long>, JpaSpecificationExecutor<MemberSettlementDO> {
    /**
     * 根据条件查询已结算数据
     * @author 伍将
     * @date 2020/11/14
     * @param settlementDate: 结算时间
     * @param memberId:会员id
     * @param roleId:会员角色id
     * @param payMemberId:支付会员id
     * @param payRoleId:支付活跃角色id
     * @param orderType:结算类型
     * @param settlementWay: 结算方式
     * @return com.ssy.lingxi.report.entity.settleaccount.MemberSettlementDO
     **/
    @Query(value = "SELECT * FROM sa_member_settlement " +
            " WHERE settlement_date=:settlementDate" +
            " AND member_id=:memberId AND role_id=:roleId" +
            " AND pay_member_id=:payMemberId AND pay_role_id=:payRoleId" +
            " AND order_type=:orderType AND settlement_Way=:settlementWay", nativeQuery = true)
    MemberSettlementDO getDetail(@Param("settlementDate") Long settlementDate, @Param("memberId") Long memberId,@Param("roleId") Long roleId,@Param("payMemberId") Long payMemberId,@Param("payRoleId") Long payRoleId,@Param("orderType") Integer orderType,@Param("settlementWay") Integer settlementWay);

    List<MemberSettlementDO> findAllByIdGreaterThanEqualAndMemberIdAndRoleIdAndOrderTypeOrderBySettlementDateAsc(Long id, Long memberId, Long roleId, Integer orderType);
}
